package com.hjsmallfly.syllabus.repository.lesson.local

import com.hjsmallfly.syllabus.ext.from_io
import com.hjsmallfly.syllabus.repository.lesson.LessonDao
import com.hjsmallfly.syllabus.repository.lesson.LessonDataSource
import com.hjsmallfly.syllabus.room.record.LessonRecord
import rx.Observable

class LessonLocalDataSource(private val lessonDao: LessonDao) : LessonDataSource {

    override fun queryLessonDetail(cid: Long, isCache: Boolean): Observable<LessonRecord> {
        return Observable.fromCallable {
            lessonDao.queryLessonById(cid)
        }.from_io()
    }

    override fun saveLesson(lesson: LessonRecord): Observable<Boolean> {
        return Observable.fromCallable {
            lessonDao.saveLesson(lesson)
            true
        }.from_io()
    }
}